import React from 'react';
import { Col, Form } from 'antd';
// import { primaryColor } from '@/defaultSettings';

export const getDictName = (value, dict) => dict.find(item => item.value === value)?.text ?? '';

export const styleTitle = title => <div style={{ fontWeight: 'bold', fontSize: 16, paddingLeft: 8 }}>{title}</div>;

export const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 }
};

export const oneLineLayout = {
    labelCol: { span: 3 },
    wrapperCol: { span: 19 }
};

export const renderItem = ({ label, value, span = 12, layout = formItemLayout }) => (
    <Col span={span}>
        <Form.Item label={label} {...layout}>
            {value}
        </Form.Item>
    </Col>
);

// 仅为了避免eslint
// eslint-disable-next-line no-confusing-arrow
export const adjustRenderItem = (EditComponent, ViewComponent, editFlag = true) =>
    editFlag ? EditComponent : ViewComponent;
